<?php
 
include "buffering.inc"; 


//Class $FileUploader;
 
//	Public  $Files;
 
//	Private $mcolFormElem;
 
 
 
//function Class_Initialize() {
 
//		Set $Files = Server.CreateObject("Scripting.Dictionary");
 
//		Set $mcolFormElem = Server.CreateObject("Scripting.Dictionary");
 
//	}
 
	   
 
//function Class_Terminate() {
 
//		if (IsObject($Files)) {
 
//			$Files.$RemoveAll();
// 
//			Set $Files = Nothing;
 
//		}
 
//		if (IsObject($mcolFormElem)) {
 
//			$mcolFormElem.$RemoveAll();
 
//			Set $mcolFormElem = Nothing;
 
//		}
 
//	}
 
 
 
//	Public Property Get Form($sIndex);
 
//		Form = "";
 
//		if ($mcolFormElem.$Exists[strtolower($sIndex)]) {Form = $mcolFormElem.$Item[strtolower($sIndex)];}
 
//	End Property;
 
 
 
//	Public Default Sub $Upload();
 
		//dim $biData, $sInputName;
 
		//dim $nPosBegin, $nPosEnd, $nPos, $vDataBounds, $nDataBoundPos;
 
		//dim $nPosFile, $nPosBound;
 
 
 
//		$biData = Request.$BinaryRead[Request.$TotalBytes];
 
//		$nPosBegin = 1;
 
//		$nPosEnd = $InstrB[$nPosBegin, $biData, CByteString(chr(13))];
 
		
 
//		if (($nPosEnd-$nPosBegin) <= 0) {break;}
 
		 
 
//		$vDataBounds = $MidB[$biData, $nPosBegin, $nPosEnd-$nPosBegin];
 
//		$nDataBoundPos = $InstrB[1, $biData, $vDataBounds];
 
		
 
//		Do Until $nDataBoundPos = $InstrB[$biData, $vDataBounds.CByteString("--")];
 
			
 
//			$nPos = $InstrB[$nDataBoundPos, $biData, CByteString("Content-Disposition")];
 
//			$nPos = $InstrB[$nPos, $biData, CByteString("name=")];
 
//			$nPosBegin = $nPos + 6;
 
//			$nPosEnd = $InstrB[$nPosBegin, $biData, CByteString(chr(34))];
 
//			$sInputName = CWideString($MidB[$biData, $nPosBegin, $nPosEnd-$nPosBegin]);
 
//			$nPosFile = $InstrB[$nDataBoundPos, $biData, CByteString("filename=")];
 
//			$nPosBound = $InstrB[$nPosEnd, $biData, $vDataBounds];
 
			
 
//			if ($nPosFile != 0 &&  $nPosFile < $nPosBound) {
 
				//dim $oUploadFile, $sFileName;
 
//				Set $oUploadFile = $New $UploadedFile;
 
				
 
//				$nPosBegin = $nPosFile + 10;
 
//				$nPosEnd =  $InstrB[$nPosBegin, $biData, CByteString(chr(34))];
 
//				$sFileName = CWideString($MidB[$biData, $nPosBegin, $nPosEnd-$nPosBegin]);
 
//				$oUploadFile.$FileName = right($sFileName, strlen($sFileName)-InStrRev($sFileName, "\"));
 
 
 
//				$nPos = $InstrB[$nPosEnd, $biData, CByteString("Content-Type:")];
 
//				$nPosBegin = $nPos + 14;
 
//				$nPosEnd = $InstrB[$nPosBegin, $biData, CByteString(chr(13))];
 
				
 
//				$oUploadFile.ContentType = CWideString($MidB[$biData, $nPosBegin, $nPosEnd-$nPosBegin]);
 
				
 
//				$nPosBegin = $nPosEnd+4;
 
//				$nPosEnd = $InstrB[$nPosBegin, $biData, $vDataBounds] - 2;
 
//				$oUploadFile.$FileData = $MidB[$biData, $nPosBegin, $nPosEnd-$nPosBegin];
 
				
 
//				if ($oUploadFile.$FileSize > 0) {$Files.$Add strtolower($sInputName), $oUploadFile;}
 
//			} else {
 
//				$nPos = $InstrB[$nPos, $biData, CByteString(chr(13))];
 
//				$nPosBegin = $nPos + 4;
 
//				$nPosEnd = $InstrB[$nPosBegin, $biData, $vDataBounds] - 2;
 
//				if (!$mcolFormElem.$Exists[strtolower($sInputName)]) {$mcolFormElem.$Add strtolower($sInputName), CWideString($MidB[$biData, $nPosBegin, $nPosEnd-$nPosBegin]);}
 
//			}
 
 
 
//			$nDataBoundPos = $InstrB[$nDataBoundPos + $LenB[$vDataBounds], $biData, $vDataBounds];
 
//		Loop;
 
//	End Sub;
 
 
 
	//String to byte string conversion
 
//function CByteString($sString) {
 
		//dim $nIndex;
 
//		for ($nIndex=1; $nIndex<=strlen($sString; $nIndex++) {);
 
//		   return  CByteString.$ChrB[$AscB[mid($sString,$nIndex,1)]];
 
//		}
 
//	}
 
 
 
	//Byte string to string conversion
 
//function CWideString($bsString) {
 
		//dim $nIndex;
 
//		return "";
 
//		for ($nIndex=1; $nIndex<=$LenB[$bsString; $nIndex++) {];
 
//		   return  CWideString.chr($AscB[$MidB[$bsString,$nIndex,1]]); 
 
//		}
 
//	}
 
//End Class;
 
 
 
//Class $UploadedFile;
 
//	Public ContentType;
 
//	Public $FileName;
 
//	Public $FileData;
 
	
 
//	Public Property Get $FileSize();
 
//		$FileSize = $LenB[$FileData];
 
//	End Property;
 
 
 
//function SaveToDisk($sPath) {
 
		//dim $oFS, $oFile;
 
		//dim $nIndex;
 
	
 
//		if ($sPath == "" || $FileName == "") {break;}
 
//		if (mid($sPath, strlen($sPath)) != "\") {$sPath = $sPath."\";}
 
	
 
//		Set $oFS = Server.CreateObject("Scripting.FileSystemObject");
 
//		if (!$oFS.$FolderExists[$sPath]) {break;}
 
		
 
//		Set $oFile = $oFS.CreateTextFile($sPath.$FileName, True);
 
		
 
		// output mechanism modified for buffering
//		$oFile.Write $BufferContent[$FileData];
 
 
 
//		$oFile.Close;
 
//	}
 
	
 
//function SaveToDatabase($ByRef $oField) {
 
//		if ($LenB[$FileData] == 0) {break;}
 
		
 
//		if (IsObject($oField)) {
 
//			$oField.$AppendChunk $FileData;
 
//		}
 
//	}
 
 
 
//End Class;
 
?>
